Opencv 图像处理 您所在的位置:网站首页 games101 opengl Opencv 图像处理

Opencv 图像处理

2022-12-15 06:48| 来源: 网络整理| 查看: 265

1.Contours函数轮廓点大小 排序

当使用findcontours后一般返回是contours, hierarchy两个,contours内包含的是根据设定模式所返回的轮廓。

最常使用:cv2.RETR_EXTERNAL,此模式只检测外轮廓。(输入图像必须先转灰度图再转二值图,这部分的阈值处理必须做好,调整好系数,使图像达到 最理想的状态)

contours的类型为列表,contours[0]存储的是轮廓的高h,contours[1]存储的是轮廓的宽w,因此可使用contours.sort(key=所需轮廓的规则,reverse=False)方法接drawcontours可对区域进行提取,其中reverse=False为升序,True为降序。

当想挑选出所有轮廓点中最小和最大值可这么写(axis是维度):

print("最小的h:",min(np.min(contours[0],axis=2))) print("最小的w:",min(np.min(contours[1],axis=2))) print("最大的h:",max(np.max(contours[0],axis=2))) print("最大的w:",max(np.max(contours[1],axis=2)))

如果此时处理得好,这就是轮廓的最大外接矩形的左上角和右下角,可以用切割法对图像进行切割。

[En]

If it is handled well at this time, this is the upper left corner and the lower right corner of the largest circumscribed rectangle of the outline, and the image can be cut by the cutting method.

fimg = img[int(minh):int(maxh),int(minw):int(maxw)]

显示图像可发现ROI被裁减出来。

2.输出contours 类型

如果各位 没有明白,那么咱们一点点来,先要确定的是contours到底是什么类型的,怎么用?

print("contours:类型:", type(contours)) print("第0 个contours:", type(contours[0]))

输入上述代码,可显示contours和contours[0]的类型,知道了对应类型,就知道该使用怎样的方式去用。

3.contours 数量

print("contours 数量:", len(contours))

输出contours的数量也是十分重要的技巧之一,观察图像和我们输出的轮廓数量,从而分析现阶段处理的轮廓是不是我们理想的情况。(我目前的项目是轮廓数越少越好,更容易处理图像)

4.contours的 具体内容

contours本身是列表类型,因此使用下面代码即可输出

print("counters:",contours[0]) print("counters:",contours[1])

其中[0]代表高h,[1]代表宽w

5.contours 轮廓点的个数

print("contours[0]点的个数:", len(contours[0])) print("contours[1]点的个数:", len(contours[1]))

( 重要*)6.循环contours点形成最小外接矩形,并绘制从而进行其他操作。

通过Opencv的几何形状函数结合轮廓点进行图形绘制。此部分放到下一篇Opencv最小外接矩形函数部分给出详细说明及代码段。

我还是有一点才华和学识,如果有什么错误,欢迎改正和交流问题!

[En]

I still have little talent and learning, if there are any mistakes, welcome to correct and communicate with the problem!

Original: https://blog.csdn.net/T_just_for_tomorrow/article/details/122695321Author: T_just_for_tomorrowTitle: Opencv 图像处理-Contours函数提取轮廓及感兴趣区域ROI的必用且实用操作技巧-(涵盖Contours的一切使用基础,附代码段)

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/254529/

转载文章受原作者版权保护。转载请注明原作者出处!



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有